package top.humbleyuan.test.level.entity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Classname HorizontalLines
 * @Description 水平线集合
 * @Date 2019/12/23 9:22
 * @Created by Yuan Huanghui
 */
public class HorizontalLines {

    // 水平线集合
    private List<HorizontalLine> horizontalLines = new ArrayList<HorizontalLine>();

    // 最低最左水平线
    private HorizontalLine lowestLine;

    private HorizontalLines(List<HorizontalLine> horizontalLines) {
        this.horizontalLines = horizontalLines;
        initLowest();
    }


    // 初始化最低水平线
    public void initLowest() {
        if(null == horizontalLines || horizontalLines.size() == 0) {
            this.lowestLine = null;
            return;
        }

        Collections.sort(this.horizontalLines, new Comparator<HorizontalLine>() {
            public int compare(HorizontalLine o1, HorizontalLine o2) {
                // 先比较Y
                if(o1.getY() < o2.getY()) {
                    return 1;
                } else if(o1.getY() > o2.getY()) {
                    return -1;
                } else {
                    // Y一样比较X
                    if(o1.getX() < o2.getX()) {
                        return 1;
                    } else if(o1.getX() > o2.getX()) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            }
        });

        this.lowestLine = this.horizontalLines.get(0);
    }

    // 临时增加水平线

}
